package com.anji.hyperneat.modular;

/**
 * Input mapper to provide support for the substrate subnet coordinates.
 * @author slusk
 *
 */
public class SubNetCoordinateInputMapper implements ICppnInputMapper {
	
	protected float vals[];
	protected int[] netArrayDimensions;
	
	/**
	 * Constructor.
	 * @param netArrayDimensions The netarray dimensions of the substrate.
	 */
	public SubNetCoordinateInputMapper(int[] netArrayDimensions) {
		this.netArrayDimensions = netArrayDimensions;
	}
	
	@Override
	public float[] getInputs() {
		return vals;
	}

	@Override
	public float[] getNormalizedInputs() {
		float[] norms = new float[vals.length];
		for (int i = 0; i < norms.length; i++) {
			if (netArrayDimensions[i] > 1)
				norms[i] = ( vals[i] / (netArrayDimensions[i] - 1) ) * 2 - 1;
			else 
				norms[i] = 0.0f;
		}
		return norms;
	}

	@Override
	public int getNumInputs() {
		return netArrayDimensions.length;
	}
	
	/**
	 * Set the coordinates for this mapper.
	 * @param vals The coordinates of the subnet.
	 */
	public void populateValues(int[] vals) {
		if (vals.length != netArrayDimensions.length) throw new IllegalArgumentException("Input array size does not match size specified at construction time.");
		this.vals = new float[vals.length];
		int idx = 0;
		for (int val : vals) {
			this.vals[idx++] = val;
		}
	}

}
